package com.itmuch.contentcenter.controller.content;

//import com.itmuch.contentcenter.auth.CheckLogin;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.itmuch.contentcenter.domain.dto.content.ShareDTO;
import com.itmuch.contentcenter.domain.user.UserDTO;
import com.itmuch.contentcenter.feignClient.UserCenterFeignClient;
import com.itmuch.contentcenter.service.content.ShareService;
import com.itmuch.contentcenter.service.content.TestService;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/shares")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ShareConroller {
    private final ShareService shareService;
    private final TestService testService;



    @GetMapping("/{id}")
//    @CheckLogin
    public ShareDTO findById(@PathVariable Integer id) {
        return this.shareService.findById(id);
    }

    /**
     * 服务调用事务测试
     */
    @GlobalTransactional(rollbackFor = Exception.class)
    @GetMapping("/test/tx")
    public void testTx() {
        this.shareService.testTx();
    }

    @GetMapping("/test")
    public String test(){
        return "test";
    }

    @GetMapping("/test-a")
    @SentinelResource(value = "test-a")
    public String testa(){
        return testService.common()+"test-a";
    }

    @GetMapping("/test-b")
    @SentinelResource(value = "test-b")
    public String testb(){
        return testService.common()+"test-b";
    }
}

